package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.domain.Platforms;
import com.ruoyi.system.api.constant.YlStatus;
import com.ruoyi.common.mapper.PlatformsMapper;
import com.ruoyi.system.service.IPlatformsService;
import org.apache.ibatis.executor.BatchResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 第三方平台表，记录对接的外部平台信息 服务实现类
 * </p>
 *
 * @author jiabao
 * @since 2025-06-26
 */
@Service
public class PlatformsServiceImpl extends ServiceImpl<PlatformsMapper, Platforms> implements IPlatformsService {

    @Override
    public List<Platforms> selectPlatformsList(Platforms platforms) {
        LambdaQueryWrapper<Platforms> query = Wrappers.lambdaQuery();
        query.like(platforms.getName()!=null,Platforms::getName, platforms.getName());
        query.like(platforms.getCode()!=null,Platforms::getCode, platforms.getCode());
        query.eq(Platforms::getStatus, YlStatus.NORMAL.getCode());
        return  this.getBaseMapper().selectList(query);
    }

    @Override
    public Platforms selectPlatformsById(Long id) {

        return this.getBaseMapper().selectById(id);
    }

    @Override
    public int insertPlatforms(Platforms platforms) {

        return this.getBaseMapper().insert(platforms);
    }

    @Override
    public int updatePlatforms(Platforms platforms) {

        return this.getBaseMapper().updateById(platforms);
    }

    @Override
    public int deletePlatformsByIds(Long[] ids) {

        List<Platforms> platforms = this.getBaseMapper().selectByIds(CollectionUtils.toList(ids));
        platforms.forEach(e -> e.setStatus(YlStatus.ABNORMAL.getCode()));
        List<BatchResult> batchResults = this.getBaseMapper().updateById(platforms);
        return 1;
    }
}